package com.ctshk.app.system.controller;

import com.ctshk.common.annotations.OperationLogAnnotation;
import com.ctshk.common.dto.Result;
import com.ctshk.common.enums.OperationLogModel;
import com.ctshk.common.enums.OperationLogType;
import com.ctshk.common.model.PageResponse;
import com.ctshk.common.web.support.BaseController;
import com.ctshk.rpc.system.dto.SysSupplierOrderMsgPageDTO;
import com.ctshk.rpc.system.req.SysSendStationInfoMsgReq;
import com.ctshk.rpc.system.req.SysSupplierOrderMsgAddReq;
import com.ctshk.rpc.system.req.SysSupplierOrderMsgDelReq;
import com.ctshk.rpc.system.req.SysSupplierOrderMsgPageReq;
import com.ctshk.rpc.system.service.ISysAssignmentMgtService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * <p>
 *  分配管理-前端控制器
 * </p>
 *
 * @author 姜斌文
 * @since 2021-03-30
 */
@Api(value="分配管理", tags="分配管理")
@RestController
@RequestMapping("/sys/assignmentMgt")
public class SysAssignmentMgtController extends BaseController {

    @DubboReference
    private ISysAssignmentMgtService assignmentMgtService;

    @ApiOperation(value = "新增分配管理", notes = "新增分配管理")
    @OperationLogAnnotation(operModul = OperationLogModel.SYSTEM, operType = OperationLogType.ADD, operTitle = "新增分配管理", operDesc = "新增分配管理")
    @PostMapping("/add")
    public Result add(@RequestBody @Valid SysSupplierOrderMsgAddReq obj) {
        assignmentMgtService.add(obj,getCurrentUser(getRequest()).getId());
        return Result.success();
    }

    @ApiOperation(value = "删除分配管理", notes = "删除分配管理")
    @OperationLogAnnotation(operModul = OperationLogModel.SYSTEM, operType = OperationLogType.DELETE, operTitle = "删除分配管理", operDesc = "删除分配管理")
    @PostMapping("/delete")
    public Result delete(@RequestBody @Valid SysSupplierOrderMsgDelReq obj) {
        assignmentMgtService.delete(obj,getCurrentUser(getRequest()).getId());
        return Result.success();
    }

    @ApiOperation(value = "修改分配管理", notes = "修改分配管理")
    @OperationLogAnnotation(operModul = OperationLogModel.SYSTEM, operType = OperationLogType.UPDATE, operTitle = "修改分配管理", operDesc = "修改分配管理")
    @PostMapping("/update")
    public Result update(@RequestBody @Valid SysSupplierOrderMsgAddReq obj) {
        assignmentMgtService.update(obj,getCurrentUser(getRequest()).getId());
        return Result.success();
    }

    @ApiOperation(value = "分页查询分配管理", notes = "分页查询分配管理")
    @OperationLogAnnotation(operModul = OperationLogModel.SYSTEM, operType = OperationLogType.QUERY, operTitle = "分页查询分配管理", operDesc = "分页查询分配管理")
    @PostMapping("/list")
    public Result<PageResponse<SysSupplierOrderMsgPageDTO>> queryList(@RequestBody SysSupplierOrderMsgPageReq supplierOrderMsgPageReq) {
        PageResponse<SysSupplierOrderMsgPageDTO> response = assignmentMgtService.assignmentMgtList(supplierOrderMsgPageReq,getCurrentUser(getRequest()));
        return Result.success(response);
    }
    
    @ApiOperation(value = "发送通知信息", notes = "发送通知信息")
    @OperationLogAnnotation(operModul = OperationLogModel.SYSTEM, operType = OperationLogType.ADD, operTitle = "发送通知信息", operDesc = "发送通知信息")
    @PostMapping("/sendNoticeInfo")
    public Result sendNoticeInfo(@RequestBody SysSendStationInfoMsgReq obj) {
        assignmentMgtService.sendStationInfo(obj,getCurrentUser(getRequest()).getId());
        return Result.success();
    }

    @ApiOperation(value = "Test-获取轮询用户", notes = "Test-获取轮询用户")
    @OperationLogAnnotation(operModul = OperationLogModel.SYSTEM, operType = OperationLogType.QUERY, operTitle = "Test-获取轮询用户", operDesc = "Test-获取轮询用户")
    @GetMapping("/getPollingUserId/{type}")
    public Result getPollingUserId(@PathVariable("type") Long type) {
       Long userId = assignmentMgtService.getPollingUserId(type);
       return Result.success(userId);
    }
}
